//
//  ByBetRecordInfoCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/13.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBetRecordInfoCell.h"
#import "ByBetRecordTitleView.h"
#import "ByBetTitleValueView.h"
#import "ByBetCirclesView.h"


@implementation ByBetRecordInfoCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByBetRecordInfoCell";
    ByBetRecordInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
}

- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    
    ByBetRecordTitleView *titleView = [[ByBetRecordTitleView alloc] init];
    [backgroundView addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@50);
    }];
    titleView.titleLabel.text = @"投注信息";
    
    UILabel *stateLabel = [[UILabel alloc] init];
    [backgroundView addSubview:stateLabel];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(10);
        make.right.equalTo(backgroundView).offset(-10);
        make.top.equalTo(titleView.mas_bottom).offset(10);
        make.height.mas_equalTo(@20);
    }];
    stateLabel.font = B_FONT(16);
    stateLabel.textColor = [UIColor blackColor];
    stateLabel.text = @"出票中";
    self.stateLabel = stateLabel;
    
    if (_netModel.pay_status.integerValue == 0) {
        self.stateLabel.text = @"未支付";

    }else if (_netModel.pay_status.integerValue == 1){

        if (_netModel.status.integerValue == -1) {
            stateLabel.text = @"已过期";
        }else if (_netModel.status.integerValue == 0){
            stateLabel.text = @"未出票";
        }else if (_netModel.status.integerValue == 1){
            stateLabel.text = @"出票中";
        }else if (_netModel.status.integerValue == 2){
            stateLabel.text = @"出票成功";
            if (_netModel.is_prize.integerValue == 0) {
                stateLabel.text = @"未开奖";
            }else if (_netModel.is_prize.integerValue == 1){

                stateLabel.text = [NSString stringWithFormat:@"已中奖！%@元", _netModel.prize_money];
                stateLabel.textColor = BY_THEME_COLOR;
            }else if (_netModel.is_prize.integerValue == 2){
                stateLabel.text = @"未中奖";
            }
        }else if (_netModel.status.integerValue == 3){
            stateLabel.text = @"出票失败";
        }


    }else if (_netModel.pay_status.integerValue == 2){
        self.stateLabel.text = @"交易关闭";

    }
    
    
   
    
    
    UILabel *lotteryLabel = [[UILabel alloc] init];
    [backgroundView addSubview:lotteryLabel];
    [lotteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.top.equalTo(backgroundView).offset(110);
        make.size.mas_equalTo(CGSizeMake(55, 15));
    }];
    lotteryLabel.textColor = [UIColor lightGrayColor];
    lotteryLabel.font = FONT(12);
    lotteryLabel.text = @"投注号码:";
    
    
    CGFloat top = 105;
    NSMutableArray *totalAry = [self.netModel.dataArray copy];
    
    for (int j = 0; j < totalAry.count; j++) {
        
    NSMutableArray *dataArray = [totalAry objectAtIndex:j];
    
    for (int i = 0; i < dataArray.count; i++) {
        
        NSMutableArray *smallArray = [dataArray objectAtIndex:i];
        ByBetCirclesView *circlesView = [[ByBetCirclesView alloc] init];
        [backgroundView addSubview:circlesView];
        
        [circlesView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lotteryLabel.mas_right).offset(0);
            make.right.equalTo(backgroundView).offset(0);
            make.top.equalTo(backgroundView).offset(top);
            make.height.mas_equalTo(@([ByBetCirclesView getHeightWithDataArray:smallArray]));
        }];
        
        top = top + [ByBetCirclesView getHeightWithDataArray:smallArray];
        if (dataArray.count == 2) {
            
            if (i == 0) {
                circlesView.titleLabel.text = @"红球:";
                circlesView.themeColor = BY_THEME_COLOR;
            }else if (i == 1){
                circlesView.titleLabel.text = @"篮球:";
                circlesView.themeColor = BY_Blue_COLOR;
            }
            
        }else if (dataArray.count == 4){
            
            if (i == 0) {
                circlesView.titleLabel.text = @"红(胆):";
                circlesView.themeColor = BY_THEME_COLOR;
            }else if (i == 1){
                circlesView.titleLabel.text = @"红(拖):";
                circlesView.themeColor = BY_THEME_COLOR;
            }else if (i == 2){
                circlesView.titleLabel.text = @"蓝(胆):";
                circlesView.themeColor = BY_Blue_COLOR;
            }else if (i == 3){
                circlesView.titleLabel.text = @"蓝(拖):";
                circlesView.themeColor = BY_Blue_COLOR;
            }
            
        }else if (dataArray.count == 3){
            
            if (i == 0) {
                circlesView.titleLabel.text = @"红(胆):";
                circlesView.themeColor = BY_THEME_COLOR;
            }else if (i == 1){
                circlesView.titleLabel.text = @"红(拖):";
                circlesView.themeColor = BY_THEME_COLOR;
            }else if (i == 2){
                circlesView.titleLabel.text = @"蓝球:";
                circlesView.themeColor = BY_Blue_COLOR;
            }
            
        }
        
        circlesView.dataArray = smallArray;
    }
        
    }
    
    for (int i = 0; i < 5; i++) {
        ByBetTitleValueView *valueView = [[ByBetTitleValueView alloc] init];
        [backgroundView addSubview:valueView];
        [valueView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.right.equalTo(backgroundView).offset(0);
            make.top.equalTo(backgroundView).offset(top + i * 30);
            make.height.mas_equalTo(@30);
        }];
        
        if (i == 0) {
            valueView.titleLabel.text = @"开奖时间:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"预计%@开奖",[NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:_netModel.will_time.integerValue]]];
            
        }else if (i == 1){
            valueView.titleLabel.text = @"投注方式:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"%@注 %@倍",_netModel.bet_num,_netModel.multiple];
        }else if (i == 2){
            valueView.titleLabel.text = @"投注金额:";
            valueView.valueLabel.text = [NSString stringWithFormat:@"%@元", _netModel.amount];
        }else if (i == 3){
            valueView.titleLabel.text = @"投注时间:";
            valueView.valueLabel.text = [NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:_netModel.add_time.integerValue]];
        }else if (i == 4){
            valueView.titleLabel.text = @"投注编号:";
            valueView.valueLabel.text = _netModel.sn;
        }
    }
    
    
}

@end
